/*
 * Created 10-mar-2005.
 */
package moon.metrics.concretemetrics;

import java.util.List;

import moon.core.NamedObject;
import moon.core.classdef.ClassDef;
import moon.core.classdef.MethDec;
import moon.metrics.core.ClassMetric;
import moon.metrics.core.Measure;

/**
 * Number of methods.
 * 
 * @author Estrella Resa Camarero and Laura Moneo Sanz
 * @version 1.0
 * @since JavaMOON 1.3
 * @see MOONMetric
 */
public class NM extends ClassMetric {

	/**
	 * Constructs a NOFP metric.
	 * 
	 * @param name
	 *            name
	 * @param description
	 *            description
	 * @param valueMin
	 *            minimum value
	 * @param valueMax
	 *            maximum value
	 */
	public NM(String name, String description, float valueMin, float valueMax) {
		super(name, description, valueMin, valueMax);
	}

	/**
	 * Constructs a NOFP metric.
	 * 
	 * @param name
	 *            name
	 * @param description
	 *            description
	 * @param author
	 *            author
	 * @param year
	 *            year
	 * @param valueMin
	 *            minimum value
	 * @param valueMax
	 *            maximum value
	 */
	public NM(String name, String description, String author, int year,
			float valueMin, float valueMax) {
		super(name, description, author, year, valueMin, valueMax);
	}

	/**
	 * Calculates the number of methods.
	 * 
	 * @param namedObject
	 *            object to measure
	 * @return measure
	 */
	public Measure run(NamedObject namedObject) {

		ClassDef cd = (ClassDef) namedObject;

		int value = methods(cd);

		Measure m = new Measure((float) value, cd, this);
		return m;
	}

	/**
	 * Solution to count the number of methods.
	 * 
	 * @param cd
	 *            class
	 * @return number of methods
	 */
	private int methods(ClassDef cd) {		
		return cd.getMethDec().size();
	}
}